package com.algorithm.chapter1.hanNuoTa;

/**
 * @Author YongQiang
 * @Date 2020/1/23 10:34
 * @Version 1.0
 */
public class HanoiProblem {
    public int hanoiProplem1(int num,String left,String mid,String right){
        if (num<1){
            return 0;
        }
        return 0;
    }

    public int process(int num,String left,String mid,String right,String from,String to){
        if (num==1){
            if (from.equals(mid) || to.equals(mid)){
                System.out.println("Move 1 from "+from+" to "+to);
                return 1;
            }
            else {
                System.out.println("Move 1 from "+from+" to "+mid);
                System.out.println("Move 1 from "+mid+" to "+to);
                return 2;
            }
        }
        if (from.equals(mid)||to.equals(mid)){
            String another=(from.equals(left)||to.equals(left))?right:left;
            int part1=process(num-1,left,mid,right,from,another);
            int part2=1;
            System.out.println("Move "+num+" from "+from+" to "+to);
            int part3=process(num-1,left,mid,right,from,to);
            return part1+part2+part3;
        }
        else {
            int part1=process(num-1,left,mid,right,from,to);
            int part2=1;
            System.out.println("Move "+num+" from "+from+" to "+mid);
            int part3=process(num-1,left,mid,right,to,from);
            int part4=1;
            System.out.println("Move "+num+" from "+mid+" to "+to);
            int part5=process(num-1,left,mid,right,from,to);
            return part1+part2+part3+part4+part5;
        }
    }
}
